package simulation;

/**
 * @author cwhalen
 * 
 */
public class Sun {
  private double longitude;

  /**
   * @param lattitude
   * @param longitude
   */
  public Sun(double longitude) {
    this.longitude = longitude;
  }

  /**
   * @return
   */
  public double getLongitude() {
    return longitude;
  }

  /**
   * @param degree
   */
  public void moveSun(double degree) {
    double tempLon = longitude + degree;

    if (tempLon > 180) {
      longitude = (-180 + (tempLon % 180));
    }
    else {
      longitude = tempLon;
    }
  }
  
  public void reset() {
    longitude = 0;
  }

  /**
   * @param tL
   * @param bL
   * @param lL
   * @param rL
   * @return
   */
  public float cRadiationFactor(float tL, float bL, float lL, float rL) {
    // Average the lattitudes and longitudes to get a middle reading to
    // compute for
    float aveLat = (tL + bL) / 2;
    float aveLon = (lL + rL) / 2;

    // Lattitude radiation will not change since the sun does not move up
    // and down in lattitude
    double latRadiation = Math.cos(Math.toRadians(aveLat));

    // Longitude radiation changes based on the lonitude movement of the sun
    double lonRadiation = Math.cos(Math.toRadians(aveLon - this.longitude));

    // FIXME : Need to propperly account for cooling. If the sun is not
    // shining on a Node then the sun's temperature is 0
    if (lonRadiation < 0) {
      return 0;// (float)((-1 * (latRadiation +(-1*lonRadiation))) /
      // 2);
    }
    else {
      // The total heat radiation will be the average of the lattitude and
      // longitude radiation
      return (float) ((latRadiation + lonRadiation) / 2);
    }
  }

}
